import request from '@/utils/request'

export function submitVote(subjectForm, principalListForm,
  optionForm, voteUserIds, voteDeptIds,
  viewUserIds, viewDeptIds) {
  let optionList = optionForm.optionList;
  for(let i = 0; i < optionList.length; i++) {
    optionList[i].optionType = optionForm.optionType;
  }
  const data = {
    subject: subjectForm,
    principalList: principalListForm.principalList,
    optionList,
    voteUserIds,
    voteDeptIds,
    viewUserIds,
    viewDeptIds,
  }

  return request({
    url: '/vote/subject/guide',
    method: 'post',
    data,
  })
}

export function listVote(query) {
  return request({
    url: '/vote/subject/mine',
    method: 'get',
    params: query
  })
}

export function delSubject(subjectIds) {
  return request({
    url: '/vote/subject/' + subjectIds,
    method: 'delete'
  })
}

export function getSubjectGuideData(subjectId) {
  return request({
    url: '/vote/subject/guide/' + subjectId,
    method: 'get',
  })
}

export function startSubject(subjectId) {
  return request({
    url: '/vote/subject/guide/start/' + subjectId,
    method: 'put'
  })
}

export function getPendingVote(query) {
  return request({
    url: '/vote/subject/pending',
    method: 'get',
    params: query
  })
}
